﻿//
//
function GetCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return(setStr);
}

function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : '/';
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" +
        expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}

function UnHideNodeItem( node_id ){
    var node = document.getElementById( node_id );
    if(node){
        node.getElementsByTagName('img')[0].src = '/fm/media/img/minus.gif';
        node.parentNode.parentNode.parentNode.className = '';  
    }
    return true;
}

function UnHideOpenNodes(){
    var sOpenNode = GetCookie('opennode'); 
    if (sOpenNode != null){
        var aOpenNode = new Array();
        aOpenNode = sOpenNode.split(';');
        for(i=0;i<(aOpenNode.length-1);i++){
            UnHideNodeItem(aOpenNode[i]);
        }
    }
}

function UnHide( eThis, path ){
    img_pm = eThis.getElementsByTagName('img')[0];
    if( img_pm.src.indexOf('plus') +1 ){
        img_pm.src = '/fm/media/img/minus.gif';
        eThis.parentNode.parentNode.parentNode.className = '';
        OpenNode = GetCookie('opennode');
        if(OpenNode != null) SetCookie('opennode', OpenNode + eThis.id + ';')
        else SetCookie('opennode', eThis.id + ';');
        
        //$(eThis.parentNode.parentNode.parentNode).find("div .dropdown-arrow")
        liNode = eThis.parentNode.parentNode.parentNode;
        $(liNode).find('ul').remove();
        $(liNode).append('<ul></ul>');
        $(liNode).find('ul').load(path);
        
    }else{
        img_pm.src = '/fm/media/img/plus.gif';
        eThis.parentNode.parentNode.parentNode.className = 'cl';
        OpenNode = GetCookie('opennode');
        if(OpenNode != null){
            var b = OpenNode.indexOf(eThis.id)
            if (b != -1){
                var sa = OpenNode.slice(0,b);
                var sb = OpenNode.slice(b+eThis.id.length+1);
                SetCookie('opennode', sa + sb);
            }
        }
        
       
        
        
    }
    //alert(GetCookie('opennode'));
    return false;
}    